package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.OperateLogMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.OperateLog;
import com.itheima.pojo.PageResult;
import com.itheima.service.OperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OperateLogServiceImpl implements OperateLogService {
    @Autowired
    private OperateLogMapper operateLogMapper;


    @Override
    public PageResult<OperateLog> page(EmpQueryParam empQueryParam) {

        //1. 设置分页参数 empQueryParam.getPage()当前页码，empQueryParam.getPageSize()每页显示的记录数
        PageHelper.startPage(empQueryParam.getPage(),empQueryParam.getPageSize());

        //2. 执行查询
        List<OperateLog> OperateLogList = operateLogMapper.selectAll();

        //3. 封装分页结果
        Page<OperateLog> p = (Page<OperateLog>) OperateLogList;
        //为什么要强转为Page<OperateLog>呢？因为Page<OperateLog>中有很多分页相关的信息，如总记录数等。
        return new PageResult(p.getTotal(), p.getResult());
        //p.getResult()获取当前页的结果集是一个List

    }
}
